package data_structure.offer;

public class Fibonacci_example {


    public static int fibonacci(int n){
        int dayOne=0;
        int dayTwo=1;
        int result=0;
        if(n==0){
            return 0;
        }
        if(n==1){
            return 1;
        }

        while(n>=2){
            result=dayOne+dayTwo;
            dayOne=dayTwo;
            dayTwo=result;
            n--;
        }

        return result;
    }

    public static int jumpFloor(int n){

        int one=2;
        int two=1;
        int result=0;

        if(n<3){
            return n;
        }
        while(n>=3){
            result=one+two;
            two=one;
            one=result;
            n--;
        }

        return result;
    }

    public static int pavBricks(int n){
        int brick=1;
        int sum=1;

        if(n==0){
            return 0;
        }
        if(n==1){
            return 1;
        }

        while(n-->=2){
            sum=sum+brick;
            brick=sum-brick;
        }
        return sum;
    }


    public static void main(String[] args) {
        int n=fibonacci(5);
        System.out.println(n);
    }
}
